﻿using AutoMapper;
using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.LeaveCommand;
using MediatR;

namespace B.S.BaseData.Read.API.CommandHandler.LeaveHandler
{
    public class QueryReasonHandler : IRequestHandler<QueryReasonCommand, APIResult<List<Record>>>
    {
        private readonly IBaseRepository<Record> reRep;
        private readonly IMapper mapper;

        public QueryReasonHandler(IBaseRepository<Record> reRep,IMapper mapper)
        {
            this.reRep = reRep;
            this.mapper = mapper;
        }
        public Task<APIResult<List<Record>>> Handle(QueryReasonCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Record>> result = new APIResult<List<Record>>();
            var list = reRep.GetAll().Where(x=>x.LeaveId==request.LeaveId);
           
            result.Code = APIEnum.Success;
            result.Msg = "查询成功";
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
